<?php
namespace Home\Common;
use Org\Util\Mysql;

class Device extends Mysql{
	//获取所有设备
	function getDevice(){
		$result = $this->mysql->prepare("select * from iry_device");
		$result->execute();
		
		$arResult = array();
		while($row = $result->fetch(\PDO::FETCH_ASSOC)){
			array_push($arResult, array($row['Id'],$row['type'],$row['number'],$row['product'],$row['info'],
						$row['mac'],$row['os'],$row['version'],$row['other']));
		}
		
		return $arResult;
	}
	//添加设备
	function addDevice($type,$number,$product,$info,$mac,$os,$version,$other){
		$insert = $this->mysql->prepare("insert into iry_device(type,number,product,info,mac,os,version,other) 
					values ('$type','$number','$product','$info','$mac','$os','$version','$other')");
		$status = $insert->execute();
		
		if($status)	return true;
		else		return false;
	}
	//搜索设备
	function sltDevice($keyword){
		$result = $this->mysql->prepare("select * from iry_device where type = \"$keyword\" or 
				number = \"$keyword\" or product = \"$keyword\" or other = \"$keyword\"");
		$result->execute();
		
		$arResult = array();
		while($row = $result->fetch(\PDO::FETCH_ASSOC)){
			array_push($arResult, array($row['Id'],$row['type'],$row['number'],$row['product'],$row['info'],
			$row['mac'],$row['os'],$row['version'],$row['other']));
		}
		
		return $arResult;
	}
}